<?php
include __DIR__ . '/conf.php';
require __DIR__ .'/vendor/myphps/myphp/base.php';

$module = ['api','chain'];
LogClient::$address = '192.168.0.245:11024';
$tList = [1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1];
$cList = [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,403,0,0,0,0,0,502,0,0,0,0,0,500,0];
for($i=0; $i<10000; $i++){
    LogClient::$referer_ip = mt_rand(1, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255);
    LogClient::$module = $module[mt_rand(0,1)];
    $c = "TestC".mt_rand(0,2); $a = 'TestA'.mt_rand(0,3); $d = mt_rand(0,2)?'TestD'.mt_rand(0,3):'';
    $name = mt_rand(0, 6)?$c.'/'.$a.($d?'/'.$d:''):'';
    LogClient::tick($name); //上报计时
    usleep(mt_rand(100000, 10000000));
    $type = $tList[mt_rand(0, count($tList)-1)];
    $code = $cList[mt_rand(0, count($cList)-1)];
    $msg = "[".date("Y-m-d H:i:s")."]".'这个是测试消息-'.mt_rand(0,20);
    var_export(LogClient::report($name, $code, $msg, $type)); //上报
}
die();
$time_start = microtime(true);
$data = LogPackage::toEncode('api','index/info', $time_start,0,0,0,'REPORT_IP');
var_dump($data); var_dump(LogPackage::decode($data));

die();
// tcp定长包读取
$post = ['cmd'=>'get_real_time','sec'=>2];
$ret = multiReadLen(['192.168.0.245:7011'=> toJson($post)]);
echo $ret['192.168.0.245:7011'],PHP_EOL;

die();

var_dump(ipCIDRCheck('192.168.0.219', '192.168.0.1/24'));
// 检测ip是否在$CIDR范围内
function ipCIDRCheck($IP, $CIDR)
{
    list($net, $mask) = explode('/', $CIDR);

    $ip_net = ip2long($net);
    $ip_mask = ~((1 << (32 - $mask)) - 1);
    var_dump($ip_mask);

    $ip_ip = ip2long($IP);
    $ip_ip_net = $ip_ip & $ip_mask;

    return ($ip_ip_net === $ip_net);
}